var order = ['red', 'yellow', 'blue', 'green', 'red']

Page({
    data: {
      toView: 'red',
      scrollTop: 100,
        imgUrls: [
            'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
            'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
            'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
        ],
        indicatorDots: false,
        autoplay: true,
        interval: 5000,
        duration: 1000,
        change_w_swiper:true,
        src:"../../dist/img/img/sprite.png",
        btn_text:"下一步",
        get_sex_btn_sel:false,//false 是女
        man_url: "http://woxiaoshitang.com/activity/Public/img/man_L.png",
        girl_url:"http://woxiaoshitang.com/activity/Public/img/female_sel_L.png",
        active_dot:0,
        now_scroll:0,
        finish_scroll:false,
        age_num_for: 
        [
          {
            num:18,
            flag:true,
          },
          {
            num: 19,
            flag: false,
          },
          {
            num: 20,
            flag: false,
          },
          {
            num: 21,
            flag: false,
          },
          {
            num: 22,
            flag: false,
          },
          {
            num: 23,
            flag: false,
          },
          {
            num: 24,
            flag: false,
          },
          {
            num: 25,
            flag: false,
          },
          {
            num: 26,
            flag: false,
          },
          {
            num: 27,
            flag: false,
          },
          {
            num: 28,
            flag: false,
          },
          {
            num: 29,
            flag: false,
          },
          {
            num: 30,
            flag: false,
          },
          {
            num: 31,
            flag: false,
          },
          {
            num: 32,
            flag: false,
          },
          {
            num: 33,
            flag: false,
          },
          {
            num: 34,
            flag: false,
          },
          {
            num: 35,
            flag: false,
          },
          {
            num: 36,
            flag: false,
          },
          {
            num: 37,
            flag: false,
          }
          , {
            num: 38,
            flag: false,
          },
          {
            num: 39,
            flag: false,
          },{
            num:40,
            flag:false
          }
          
          ],
        age_num:18,  
        cm:100,
        school_mess_top_nam:"华南师范大学",
        school_id:1,
        school_mess:[{
          name:"华师",
          id:1,
          image:"5937adc31b2a0.jpg"
        },
          {
            name: "华师",
            id: 1,
            image: "5937adc31b2a0.jpg"
          }
          ],
        school_img_src_bas:"http://woxiaoshitang.com/activity/Public/upload/Wx/",
        school_len:1,
        next_text:"下一步",
        height_img:"../../img/height_.jpg",
        scrol_left:30,
        kg:30,
        weight_scrol_left:30,
        set_scroll_school_left:30,
        age_num_for_length:22,
        age_tousctart:0,//设置一个回弹
    },
    man_tap:function(){
      console.log(this.data.get_sex_btn_sel);
      if(this.data.get_sex_btn_sel == false){
        // console.log("yes")
        this.setData({
          man_url:"http://woxiaoshitang.com/activity/Public/img/man_sel_L.png",
          girl_url:"http://woxiaoshitang.com/activity/Public/img/female_L.png",
          get_sex_btn_sel:true
        })
      }else{
        this.setData({
          man_url: "http://woxiaoshitang.com/activity/Public/img/man_L.png",
          girl_url:"http://woxiaoshitang.com/activity/Public/img/female_sel_L.png",
          get_sex_btn_sel:false
        })
      }
    },
    next:function(){
      // console.log("next")
      wx.navigateTo({
        url: '../get_age/get_age'
      })
    },
    changeAutoplay: function(e) {
        console.log("changeAutoplay")
        this.setData({
            autoplay: !this.data.autoplay
        })
    },
    intervalChange: function(e) {
        console.log("intervalChange")
        this.setData({
            interval: e.detail.value
        })
    },
    durationChange: function(e) {
        console.log("durationChange")
        this.setData({
            duration: e.detail.value
        })
    },
    // get_age_scroll
    scroll_left:function(){
      console.log("scroll_left")
    },
    scroll_right:function(){
      console.log("scroll_right");
    },
    touch_start : function(e){
      // console.log(e)
      console.log("touch_start");
      console.log(e);
      console.log("target");
      console.log(e.target.offsetLeft);
      
    },
    touch_end : function(e){
        // console.log("toch)end");
        // console.log(e);
        // console.log(e.target.offsetLeft)
    },
    age_touch_move:function(e){
        // console.log("touch_Mvoe")
        // conosle.log(e)
    },
    get_scroll: function (e) {
      let age_num_for = this.data.age_num_for
      var c_num = (e.detail.scrollWidth * 0.89) / 22
      var num = parseInt(e.detail.scrollLeft / c_num)
      for (var i = 0; i < age_num_for.length; i++) {
        age_num_for[i].flag = false;
      }
      age_num_for[num].flag = true;
      
      this.setData({
        age_num: parseInt(e.detail.scrollLeft / c_num) + 18,
        age_num_for: age_num_for
        // age_num_for_length: age_num_for.length
      })
      // console.log(window.devicePixelRatio)
    },
    get_scroll_height:function(e){
      var cut_Num = e.detail.scrollWidth * 0.006
      var count_num = e.detail.scrollWidth * 0.0068;
    
      this.setData({
        cm: parseInt((e.detail.scrollLeft - cut_Num) / count_num) + 100
      })
      // this.setData({
      //   cm: parseInt((e.detail.scrollLeft -8)/10)+100
      // })
    },
    get_scroll_weight:function(e){
      // console.log("weight")
      // console.log(e.detail.scrollWidth)
      var cut_Num_w = e.detail.scrollWidth *0.01
      var count_num_w = e.detail.scrollWidth * 0.0089;
      // console.log(cut_Num)
      // console.log(count_num)
       console.log((e.detail.scrollLeft - cut_Num_w) / count_num_w)
      this.setData({
        kg: parseInt((e.detail.scrollLeft - cut_Num_w) / count_num_w) + 30
      })
    },
    next:function(){
      var data = this.data.active_dot
      data++;
      if(data == 4){//获取学校
        wx.showLoading({
          mask:true,
          title:'加载中',
          // btn_text:"完成"
        })
        var _this = this;
        wx.request({
          url: 'https://woxiaoshitang.com/activity/health.php/applet/getschool',
          header: {
            'content-type': 'application/json'
          },
          // method:"post"
          success: function (res) {
            _this.setData({
              school_mess:res.data,
              school_len:res.data.length,
              btn_text: "完成"
            })
            setTimeout(function () {
              wx.hideLoading()
            },100)
          },fail:function(data){
               console.log(data)
              wx.hideLoading()
               
          }
        })
      }
      if(data == 5){//提交信息
        wx.showLoading({
          mask:false,
          title: '加载中'
        })
        try {
          var schoolid = this.data.school_id
          var weight =this.data.kg;
          var height = this.data.cm;
          var age = this.data.age_num;
          var sex = this.data.get_sex_btn_sel == false? 0 :1;
          var value = wx.getStorageSync('time');
          var step = wx.getStorageSync('stepnumber');
          var openid = wx.getStorageSync('openid');
          var userid = wx.getStorageSync('userid');
          console.log(step)
          if (value) {
            // Do something with return value
            var  time = value
          }
        } catch (e) {
          console.log(e)
          // Do something when catch error
        }
        wx.request({
          url: 'https://woxiaoshitang.com/activity/health.php/applet/setuserinfo',
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          method:"post",
          data:{
            schoolid: schoolid,
            datatime: time,
            step: step,
            openid: openid,
            userid: userid,
            weight: weight,
            height: height,
            age:age,
            sex:sex
          },
          success: function (res) {
            wx.hideLoading();
            console.log("suceess")
            var x = {schoolid: schoolid,
              datatime: time,
              step: step,
              openid: openid,
              userid: userid,
              weight: weight,
              height: height,
              age: age,
              sex: sex}
            console.log(x)
            console.log(res);
            wx.redirectTo({
              url: "../healthy/healthy"
            });
            setTimeout(function () {
              wx.hideLoading();
              
            }, 0)
          },fail:function(e){
            var x = {
              schoolid: schoolid,
              datatime: time,
              step: step,
              openid: openid,
              userid: userid,
              weight: weight,
              height: height,
              age: age,
              sex: sex
            }
            console.log(x)
            console.log(e)
            wx.hideLoading();
            wx.showToast({
              title:"网络出错"
            })
          }
        })
        return;touch
      }
     
      this.setData({
        active_dot:data 
      })
      if (data == 2) {
        // console.log(333333333333333)
        this.setData({
          scrol_left: 7.5
        })
      }
      if(data == 3){//体重
        this.setData({
          weight_scrol_left: 12.5
        })
        setTimeout(()=>{
          this.setData({
            kg: 30
          })
        },0)
      }
    },
    get_scroll_school(e){
      var school_mess = this.data.school_mess;
      var num = parseInt((e.detail.scrollLeft) / 140); 
      this.setData({
        school_mess_top_nam: school_mess[num].name,
         school_id: school_mess[num].id
      })
    }
})
